package com.sjq.project.web;

import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sjq.common.entity.LoginAccount;
import com.sjq.common.util.PageResults;
import com.sjq.common.web.SessionUserHelper;
import com.sjq.project.entity.ProjectBudget;
import com.sjq.project.entity.ProjectBudgetList;
import com.sjq.project.service.ProjectBudgetService;

@Controller
public class ProjectBudgetController {
	@Autowired
    private ProjectBudgetService projectBudgetService;
    @Autowired
    private HttpSession session;  
    private static final String INITURL = "projectBudget/"; 
   /**查询列表***/
   @RequestMapping(INITURL+"ProjectBudgetList")
   @ResponseBody
   public JSONObject  ProjectBudgetList(Integer pageNo, Integer pageSize, ProjectBudget projectBudget){
 	  if(projectBudget==null){
    		projectBudget=new ProjectBudget();
    	}
   	   pageNo = pageNo == null ? 1 : pageNo;
       PageResults<?> pageResults=projectBudgetService.findProjectBudgetByPage(pageNo, PageResults.ALLPAGESIZE, projectBudget);
       JSONObject json=new JSONObject();
       json.put("dataList", pageResults.getResults());
       json.put("pageNo",  pageResults.getPageNo());
       json.put("pages", pageResults.getPageCount());
       return json;
   }
   
    /**提交表单---不含文件**/
    @RequestMapping(INITURL+"addProjectBudget")
	@ResponseBody
	 public JSONObject addProjectBudget(ProjectBudget projectBudget) {
	   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       LoginAccount la= helper.getLoginAccount();
       return projectBudgetService.addProjectBudget(projectBudget, la);
    }
    @RequestMapping(INITURL+"addProjectBudget2")
	@ResponseBody 
	 public JSONObject addProjectBudget2(String xxzjbh,ProjectBudgetList  projectBudget) {
    	
       System.out.println("----------");
	   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       LoginAccount la= helper.getLoginAccount();
       return projectBudgetService.addProjectBudget2(xxzjbh,projectBudget, la);
    }
    
    /**删除信息**/
     @RequestMapping(INITURL+"deleteProjectBudget")
	 @ResponseBody
	 public JSONObject deleteProjectBudget(String projectBudgetId) {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        return projectBudgetService.deleteProjectBudget(projectBudgetId,la);
    }	
    
    
    /**更新表单**/
     @RequestMapping(INITURL+"motifyProjectBudget")
	 @ResponseBody
	 public JSONObject motifyProjectBudget(ProjectBudget projectBudget) {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        return  projectBudgetService.updateProjectBudget(projectBudget,la);   
    }	
    
    
     /**
    * @description 根据查询条件查询表的所有详细信息
    **/
	@RequestMapping(INITURL+"findProjectBudgetAllList")
    @ResponseBody
    public JSONObject  findProjectBudgetAllList(ProjectBudget projectBudget){
 		   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       	   LoginAccount la= helper.getLoginAccount();
		   return  projectBudgetService.findProjectBudgetByListAll(projectBudget,la);  	
     }
   
   
}
